package com.d2.modules.system.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.d2.modules.system.dict.entity.Dict;
import com.d2.modules.system.dict.entity.DictItem;
import com.d2.modules.system.dict.mapper.IDictItemMapper;
import com.d2.modules.system.dict.mapper.IDictMapper;
import com.d2.modules.system.dict.service.DictItemService;
import com.d2.modules.system.dict.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DictServiceImpl extends ServiceImpl<IDictMapper, Dict> implements DictService {
    @Autowired
    private DictItemService dictItemService;

    @Override
    public String translate(String code, Object value) {
        Dict dict = getByCode(code);
        DictItem query = new DictItem();
        query.setDictId(dict.getId());
        return dictItemService.getOne(Wrappers.lambdaQuery(query)).getValue();
    }

    public Dict getByCode(String code){
        Dict query = new Dict();
        query.setCode(code);
        return this.getOne(Wrappers.lambdaQuery(query));
    }
}
